package com.example.bili.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.bili.R;
import com.example.bili.allbean.HisplaypageBean;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

/**
 * 作    者 ： 文欢
 * 时    间 ： 2017/3/10.
 * 描    述 ：
 * 修改时间 ：
 */

public class WHisplayPageAdapter10 extends RecyclerView.Adapter<WHisplayPageAdapter10.MyViewHolder>{
    Context context;
    List<HisplaypageBean.ResultBean.PreviousBean.ListBean> list;
    private OnRVitemClickListener onRVitemClickListener;

    public WHisplayPageAdapter10(Context context, List<HisplaypageBean.ResultBean.PreviousBean.ListBean> list) {
        this.context = context;
        this.list = list;
    }

    public void addList(List<HisplaypageBean.ResultBean.PreviousBean.ListBean> list) {
        this.list.clear();
        this.list.addAll(list);
        this.notifyDataSetChanged();
    }
    @Override
    public WHisplayPageAdapter10.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder myViewHolder = new MyViewHolder(LayoutInflater.from(
                context).inflate(R.layout.w_hisplaypage_ritem2, parent, false));

        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(WHisplayPageAdapter10.MyViewHolder holder, final int position) {
        holder.textView.setText(list.get(position).getTitle());
        holder.imageView.setImageURI(list.get(position).getCover());
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onRVitemClickListener.onClickListener(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }



    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView textView;
        SimpleDraweeView imageView;
        public MyViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.item2_tv);
            imageView = (SimpleDraweeView) itemView.findViewById(R.id.item2_iv);
        }
    }

    public interface OnRVitemClickListener{
        void onClickListener(int position);
    }

    public void setOnRVitemClickListener(OnRVitemClickListener onRVitemClickListener){

        this.onRVitemClickListener = onRVitemClickListener;


    }
}
